import RequestAnimationFrame from './mock-animationframe'

export default class JankAnimation {
  animation: RequestAnimationFrame
  private counter = 0
  private readonly maxJankFrame = 40

  constructor() {
    this.animation = new RequestAnimationFrame({
      fps: 10,
    })
  }

  setup() {
    const cb = () => {
      this.counter++
      if (this.counter > this.maxJankFrame) {
        this.animation.setFps(60)
      } else {
        this.animation.requestAnimationFrame(cb)
      }
    }

    this.animation.requestAnimationFrame(cb)
  }
}
